from module.aaa_example import example
from flask import request, render_template, send_from_directory
import os

@example.route("/upload_file", methods=["POST", "GET"])
def upload():
    if request.method == "POST":
        f = request.files["file"]
        basepath = os.getcwd()
        upload_path = os.path.join(basepath, "data/uploads", f.filename)
        f.save(upload_path)
        print("uploading ...")
        # return redirect(url_for('download'))
    return render_template("/aaa_example/index.html")


@example.route("/download_file")
def download():
    file_path=request.args.get("file_path")
    if file_path is None :
        return "没有此文件"
    if os.path.exists(file_path) :
        (file_dir, file_name) = os.path.split(file_path)
        return send_from_directory(file_dir, file_name, as_attachment=True)
    else:
        return "没有此文件"